<template>
  <div>
    <slot />
  </div>
</template>

<script setup>
import $common from "@/utils/$common";
const props = defineProps({
  form: {
    default: () => {
      return {};
    },
  },
});

function validate() {
  return new Promise((resolve, reject) => {
    let arr = [];
    for (let i = 0; i < childList.length; i++) {
      let item = childList[i];
      if (item.$props?.prop && item.$props?.rule?.required) {
        arr.push(item.validatorChild(props.form[item.$props.prop]));
      }
    }

    Promise.all(arr).then((res) => {
      let errorList = res.filter((item) => item);
      if (errorList.length) {
        reject(errorList);
      } else {
        resolve(true);
      }
    });
  });
}
let childList = $ref([]);
function getChild(child) {
  childList.push(child);
}

function delChild(child) {
  let selfIndex = childList.findIndex((v) => v.ctxId == child.ctxId);
  console.log(selfIndex);
  if (selfIndex != -1) {
    childList.splice(selfIndex, 1);
  }
}

defineExpose({
  validate,
  getChild,

  delChild,
});
</script>
<style lang="scss" scoped></style>
